from django.db import models


class Questionnaire(models.Model):
    """问卷"""
    questionnaire_name = models.CharField(max_length=200, blank=False, null=False, unique=True, default='问卷', help_text='问卷标题')
    questionnaire_description = models.CharField(max_length=200, blank=True, null=True, default='问卷描述', help_text='问卷描述')
    questionnaire_status = models.IntegerField(blank=True, null=True, default=1)
    create_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.questionnaire_name

    class Meta:
        db_table = 'questionnaire'
        verbose_name = '问卷'
        verbose_name_plural = '问卷'


class Question(models.Model):
    """问题"""
    questionnaire = models.ForeignKey(Questionnaire, help_text='所属问卷', on_delete=models.CASCADE)
    question_text = models.CharField(max_length=200, blank=False, null=False, default='问题', help_text='问题')
    required_question = models.BooleanField(blank=False, null=False, default=False, help_text='是否必填')

    def __str__(self):
        return "问题-"+((self.question_text[:5]+'...') if len(self.question_text) > 7 else self.question_text)


class Answer(models.Model):
    """答案"""
    question = models.ForeignKey(Question, help_text='所属问题', on_delete=models.CASCADE)
    answer_text = models.CharField(max_length=200, blank=False, null=False, default='答案', help_text='答案')
    create_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "答案-"+((self.answer_text[:5]+'...') if len(self.answer_text) > 7 else self.answer_text)

